import 'package:bruno/bruno.dart';
import 'package:flutter/cupertino.dart';

/**
 * 身份证验证
 */
import 'package:flutter/material.dart';
import 'package:flutter_boost/flutter_boost.dart';
import 'package:xiongmao_clean_flutter_module/res/gaps.dart';

import '../../../../res/colors.dart';

/**
 * 这里是入职的审批规则
 *
 */
class AppEntryDepartMainPage extends StatefulWidget {
  final int position;

  AppEntryDepartMainPage({Key? key, this.position = 0}) : super(key: key);

  @override
  _AppEntryDepartMainPageState createState() => _AppEntryDepartMainPageState();
}

class _AppEntryDepartMainPageState extends State<AppEntryDepartMainPage> {
  List<String> items = ['开始审批', 'Item 1', 'Item 2', 'Item 3', '结束审批'];

  bool isDragging = false; //监听移动的动作

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colours.base_primary_bg_page,
      appBar: BrnAppBar(
        title: '编辑审批节点',
        backLeadCallback: () {
          BoostNavigator.instance.pop();
        },
      ),
      body: Container(
        margin: EdgeInsets.only(top: 10, bottom: 10),
        child: Column(children: [

          ReorderableListView(
            onReorder: (oldIndex, newIndex) {
              if ((oldIndex != 0 && newIndex != 0) && (oldIndex != items.length - 1) && (newIndex != items.length)) {
                setState(() {
                  if (oldIndex < newIndex) {
                    newIndex -= 1;
                  }
                  final item = items.removeAt(oldIndex);
                  items.insert(newIndex, item);
                });
              }
              setState(() {
                isDragging = false;
              });
            },
            onReorderStart: (index) {
              setState(() {
                isDragging = true;
              });
            },
            children: items.asMap().entries.map((entry) {
              final index = entry.key;
              final item = entry.value;

              return Column(
                key: ValueKey(item),
                children: [
                  Container(
                    padding: EdgeInsets.only(top: 10, bottom: 10, left: 10, right: 10),
                    color: Colors.white,
                    child: Row(
                      children: [
                        Opacity(
                          opacity: (index != 0 && index != items.length - 1) ? 1.0 : 0.0, // 根据条件设置不透明度
                          child: const Icon(
                            Icons.drag_handle,
                            size: 18,
                          ),
                        ),
                        Gaps.hGap10,
                        Expanded(
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start, // 文字靠右对齐
                            children: [
                              Text(
                                item,
                                style: TextStyle(color: (index != 0 && index != items.length - 1) ? Colours.base_primary_jv : Colours.base_primary_text_hint, fontWeight: FontWeight.bold),
                              ),
                              Visibility(
                                visible: (index != 0 && index != items.length - 1),
                                child: Text(item),
                              ),
                            ],
                          ),
                        ),
                        Opacity(
                            opacity: (index != 0 && index != items.length - 1) ? 1.0 : 0.0,
                            child: IconButton(
                              icon: Image.asset(
                                'assets/images/base/icon_base_edit.png',
                                width: 26,
                                height: 26,
                              ),
                              onPressed: () {
                                // 编辑操作
                                BoostNavigator.instance.push("appSettingsMainPage");
                              },
                            )),
                        Opacity(
                            opacity: (index != 0 && index != items.length - 1) ? 1.0 : 0.0,
                            child: IconButton(
                              icon: Image.asset(
                                'assets/images/base/icon_base_red_del.png',
                                width: 26,
                                height: 26,
                              ),
                              onPressed: () {
                                // 删除操作
                              },
                            )),
                      ],
                    ),
                  ),
                  Visibility(
                    visible: (index != items.length - 1),
                    child: Container(
                      width: double.infinity, // 将Container宽度设置为父级容器的宽度
                      color: Colours.base_primary_bg_page,
                      child: InkWell(
                        child: Image.asset(
                          'assets/images/common/icon_approve.png',
                          height: 40,
                        ),
                        onTap: () {
                          BoostNavigator.instance.push("appSettingsMainPage");
                        },
                      ),
                    ),
                  ),
                ],
              );
            }).toList(),
          )
        ],),
      ),
      bottomNavigationBar: Container(
        height: 60,
        color: Colors.white,
        padding: EdgeInsets.only(left: 16, right: 16, top: 10, bottom: 10),
        child: BrnBigMainButton(
          bgColor: Colours.base_primary_green,
          title: '提交',
          onTap: () {
            BrnToast.show('点击', context);
          },
        ),
      ),
    );
  }
}
